package com.firesyde.gwt.persistence.guice.hibernate;

import org.hibernate.Session;
import org.hibernate.cfg.Configuration;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import com.firesyde.gwt.persistence.IDataManager;
import com.firesyde.gwt.persistence.client.StorableDAO;
import com.firesyde.gwt.persistence.hibernate.HibernateDataManager;
import com.google.inject.AbstractModule;
import com.google.inject.TypeLiteral;

/**
 * Simple module to inject Berkeley DB Java Edition database/environment/catalog objects
 * @author dan
 *
 */
public class HibernateModule extends AbstractModule {

//	private String configFile;
	private Configuration config;
	
	//hide the no-arg constructor
//	private HibernateModule() {
//	
//	}
	
	public HibernateModule() {
		super();
	}
	
	@Override
	protected void configure() {
		config = new Configuration();
		config.configure();
//		config.addResource(configFile);
//		config.setProperty("hibernate.dialect", dialect);
//		config.setProperty("hibernate.connection.datasource", connectionString);
		
		bind(Configuration.class).toInstance(config);
		
		bind(Session.class).toProvider(new HibernateSessionProvider(config));
		
		bind(IDataManager.class).to(HibernateDataManager.class);
//		bind(new TypeLiteral<IDataManager<? extends StorableDAO>>() {}).toProvider(new HibernateDataManagerProvider<StorableDAO>());
		
		//logging XXX totally lazy!
		bind(Logger.class).toInstance(LoggerFactory.getLogger(HibernateModule.class));
	}

}
